import React from "react";
import {Tooltip, Popover, message, Badge, Divider, Icon, Popconfirm, Progress, Rate, Select, Tag} from 'antd'
import moment from 'moment';


const Option = Select.Option;


export default {
  showMessage: (type, time, callback) => {
    message[type](`恭喜你,这个是${type}`, time).then((res) => {
      if (callback) {
        callback()
      }
    })
  },

  // 操作
  operation(_this) {
    return (text, record, index) => {
      return <div>
        <a onClick={() => _this.openOrderMapPage(record.id)}><Icon type="edit"
                                                                   style={{marginRight: 2}}/>订单详情</a>
        <Divider type="vertical"/>
        <Popconfirm placement="rightBottom" title="数据删除将不可以恢复,确定删除?" onConfirm={_this.handleLineDelete}
                    cancelText="否" okText="是">
          <a href=""><Icon type="delete" style={{marginRight: 2}}/>删除</a>
        </Popconfirm>
        <Divider type="vertical"/>
        <a onClick={_this.handleLineDelete}> <Icon type="delete" style={{marginRight: 2}}/>结束订单</a>
        {/* <Divider type="vertical"/> */}
        {/*<a onClick={() => this.handleOperator('detail')}>员工详情</a>*/}
      </div>
    }
  },

  //分页快捷封装
  pagination(paginationData, callback, callback2) {
    // console.log(paginationData)
    return {
      defaultPageSize: 10,	                                  //默认的每页条数
      defaultCurrent: 1,                                        //默认的当前页数
      current: paginationData.content.page.page,                //当前页数
      pageSize: paginationData.content.page.size,               //每页条数
      total: paginationData.content.page.total,                 //数据总数
      showQuickJumper: true,                                    //是否可以快速跳转至某页
      showSizeChanger: true,                                    //是否可以改变 pageSize,可以联合pageSizeOptions使用
      pageSizeOptions: ['10', '20', '50', '100'],	              //指定每页可以显示多少条
      size: "small",                                            //当为「small」时，是小尺寸分页
      hideOnSinglePage: false,                                   //只有一页时是否隐藏分页器
      disabled: false,                                          //禁用分页
      // simple:true,                                           //当添加该属性时，显示为简单分页
      showTotal: () => {
        return `共${paginationData.content.page.total}条`;
      },

      onChange: (current, size) => {                            //页码改变的回调，参数是改变后的页码及每页条数 Function(page, pageSize)
        callback(current, size, "onChange");
      },

      onShowSizeChange: (current, size) => {                   //pageSize 变化的回调  Function(current, size)
        callback(current, size, "onShowSizeChange");
      },

      // onShowSizeChange: (current, size) => {                //pageSize 变化的回调  Function(current, size)
      //   let newPage = this.props.capital.page;
      //   newPage.size = size;
      //   newPage.page = 1;
      //   this.props.dispatch({
      //     type: 'capital/getStatementsList',
      //     payload: {
      //       customerno: values.customerno,
      //       stateno: values.stateno,
      //       status: values.status,
      //       beginTime: beginTime,
      //       endTime: endTime,
      //       minamount: values.minamount,
      //       maxamount: values.maxamount,
      //       creator: values.creator,
      //       page: newPage
      //     }
      //   });
      // },

    };
  },

  getOptionList(data) {
    if (!data) {
      return [];
    }
    let options = [] //[<Option value="0" key="all_key">全部</Option>];
    data.map((item) => {
      options.push(<Option value={item.value} key={item.value}>{item.name}</Option>)
    })
    return options;
  },


  tooltip: (oData) => <span>{oData["title"]}&nbsp;<Tooltip title={oData["help"]}><Icon
    type="question-circle-o"/></Tooltip></span>,


  //徽章
  badge: (data) => (params) => {
    let obj = {}
    if (data) {
      for (let k in data) {
        obj[k] = <Badge  {...data[k]} />
      }
    }
    return obj[params]
  },


  ropover: (data) => (text, record, index) => (
    <Popover arrowPointAtCenter placement="top" title={text} content={record[data]}
             trigger="click"><a>{text}</a></Popover>),

  //时间格式化
  moment: (timeFormat) => (params) => {
    if (!timeFormat) {
      var timeFormat = 'YYYY-MM-DD hh:mm:ss'
    }
    return <span>{moment(params).format(timeFormat)}</span>;
  },


  //评分
  rate: () => (params) => <Rate allowHalf defaultValue={Math.round(params / 12)}/>,

  //圆形进度
  progressCircle: () => (params) => <Progress type="circle" percent={params} width={40}/>,

  //标签
  tag: (data) => (params) => {
    if (data) {
      var obj = {}
      for (let k in data) {
        obj[k] = < span> <Tag key={params} {...data[k]}>{data[k].text||'未知'}</Tag></span>
      }
    }
    return obj[params]
  },

}
